package com.adee.nowcoder.huawei;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class T043_HJ043 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int m = in.nextInt();
            int n = in.nextInt();
            int[][] arr = new int[m][n];
            // 构造矩阵
            for(int i = 0; i < m; i++) {
                for(int j = 0; j < n; j++) {
                    arr[i][j] = in.nextInt();
                }
            }

            // bfs
            LinkedList<Pos> q = new LinkedList<>();
            q.add(new Pos(0,0,null));
            arr[0][0] = 1;
            Pos last = null;
            while(q.size() > 0) {
                Pos pos = q.get(0);
                int x = pos.x;
                int y = pos.y;
                if(x == m-1 && y == n-1) {
                    last = pos;
                    break;
                }
                q.remove(0);
                // 左
                if(y > 0 && arr[x][y-1] == 0) {
                    arr[x][y-1] = 1;
                    q.add(new Pos(x, y-1, pos));
                }
                // 右
                if(y < n-1 && arr[x][y+1] == 0) {
                    arr[x][y+1] = 1;
                    q.add(new Pos(x, y+1, pos));
                }
                // 上
                if(x > 0 && arr[x-1][y] == 0) {
                    arr[x-1][y] = 1;
                    q.add(new Pos(x-1, y, pos));
                }
                // 下
                if(x < m-1 && arr[x+1][y] == 0) {
                    arr[x+1][y] = 1;
                    q.add(new Pos(x+1, y, pos));
                }
            }
            List<Pos> list = new ArrayList<>();
            while(last != null) {
                list.add(last);
                last = last.father;
            }

            for(int i = list.size()-1; i >= 0; i--) {
                Pos p = list.get(i);
                System.out.println("(" + p.x + "," + p.y + ")");
            }
        }
    }

    static class Pos {
        int x;
        int y;
        Pos father;
        public Pos(int x, int y, Pos father) {
            this.x = x;
            this.y = y;
            this.father = father;
        }
    }
}
